Ext.onReady(function() {
	
	Ext.apply(Function.prototype,{
	
	createDelegate:function(obj, args, appendArgs) {
				var method = this;
				
				return function() {
					var callArgs = args || arguments;
					
					if (appendArgs === true) {
						callArgs = Array.prototype.slice.call(arguments, 0);						
						callArgs = callArgs.concat(args);
						//console.dir(callArgs);
					} else if (Ext.isNumber(appendArgs)) {
						callArgs = Array.prototype.slice.call(arguments, 0);
						var applyArgs = [appendArgs, 0].concat(args);
						Array.prototype.splice.apply(callArgs, applyArgs);
					}
					return method.apply(obj || window, callArgs);
				};
	}
			})

	var sayHi = function(person) {
		// Note this use of "this.text" here. This function expects to
		// execute within a scope that contains a text property. In this
		// example, the "this" variable is pointing to the btn object
		// that
		// was passed in createDelegate below.
		alert('Hi, ' + arguments[0].text + '. You clicked the "' + this.text + '" button.');
	}
 
	var btn = new Ext.Button({
				text : 'Say Hi',
				renderTo : Ext.getBody()
			});

	// This callback will execute in the scope of the
	// button instance. Clicking the button alerts
	// "Hi, Fred. You clicked the "Say Hi" button."
	btn.on('click', sayHi.createDelegate(btn, ['Fred'], true));
})